From a5bf3b888df56ad09c01574d036c0714dde20bcc Mon Sep 17 00:00:00 2001 From: Niko Matsakis Date: Wed, 11 Jan 2017 11:20:36 -0500 Subject: [PATCH] check for `CARGO_INCREMENTAL` and pass `-Zincremental` if present --- src/cargo/ops/cargo_rustc/context.rs | 15 +++++++++++++++ src/cargo/ops/cargo_rustc/layout.rs | 8 ++++++++ src/cargo/ops/cargo_rustc/mod.rs | 1 + tests/build.rs | 18 ++++++++++++++++++ 4 files changed, 42 insertions(+) diff --git a/src/cargo/ops/cargo_rustc/context.rs b/src/cargo/ops/cargo_rustc/context.rs index a5a16b479..c3f4212e2 100644 --- a/src/cargo/ops/cargo_rustc/context.rs +++ b/src/cargo/ops/cargo_rustc/context.rs @@ -48,6 +48,7 @@ pub struct Context<'a, 'cfg: 'a> { target_info: TargetInfo, host_info: TargetInfo, profiles: &'a Profiles, + incremental_enabled: bool, } #[derive(Clone, Default)] @@ -74,6 +75,11 @@ impl<'a, 'cfg> Context<'a, 'cfg> { None => None, }; + // Enable incremental builds if the user opts in. For now, + // this is an environment variable until things stabilize a + // bit more. + let incremental_enabled = env::var("CARGO_INCREMENTAL").is_ok(); + Ok(Context { ws: ws, host: host_layout, @@ -93,6 +99,7 @@ impl<'a, 'cfg> Context<'a, 'cfg> { build_explicit_deps: HashMap::new(), links: Links::new(), used_in_plugin: HashSet::new(), + incremental_enabled: incremental_enabled, }) } @@ -843,6 +850,14 @@ impl<'a, 'cfg> Context<'a, 'cfg> { self.lib_profile() } + pub fn incremental_args(&self, _unit: &Unit) -> CargoResult> { + if self.incremental_enabled { + Ok(vec![format!("-Zincremental={}", self.host.incremental().display())]) + } else { + Ok(vec![]) + } + } + pub fn rustflags_args(&self, unit: &Unit) -> CargoResult> { env_args(self.config, &self.build_config, unit.kind, "RUSTFLAGS") } diff --git a/src/cargo/ops/cargo_rustc/layout.rs b/src/cargo/ops/cargo_rustc/layout.rs index 2b5cd7514..a3570042e 100644 --- a/src/cargo/ops/cargo_rustc/layout.rs +++ b/src/cargo/ops/cargo_rustc/layout.rs @@ -40,6 +40,10 @@ //! $pkg2/ //! $pkg3/ //! +//! # Directory used to store incremental data for the compiler (when +//! # incremental is enabled. +//! incremental/ +//! //! # Hidden directory that holds all of the fingerprint files for all //! # packages //! .fingerprint/ @@ -57,6 +61,7 @@ pub struct Layout { deps: PathBuf, native: PathBuf, build: PathBuf, + incremental: PathBuf, fingerprint: PathBuf, examples: PathBuf, _lock: FileLock, @@ -88,6 +93,7 @@ impl Layout { deps: root.join("deps"), native: root.join("native"), build: root.join("build"), + incremental: root.join("incremental"), fingerprint: root.join(".fingerprint"), examples: root.join("examples"), root: root, @@ -102,6 +108,7 @@ impl Layout { mkdir(&self.deps)?; mkdir(&self.native)?; + mkdir(&self.incremental)?; mkdir(&self.fingerprint)?; mkdir(&self.examples)?; mkdir(&self.build)?; @@ -120,6 +127,7 @@ impl Layout { pub fn deps(&self) -> &Path { &self.deps } pub fn examples(&self) -> &Path { &self.examples } pub fn root(&self) -> &Path { &self.root } + pub fn incremental(&self) -> &Path { &self.incremental } pub fn fingerprint(&self) -> &Path { &self.fingerprint } pub fn build(&self) -> &Path { &self.build } } diff --git a/src/cargo/ops/cargo_rustc/mod.rs b/src/cargo/ops/cargo_rustc/mod.rs index adbdbedc3..4bcf363df 100644 --- a/src/cargo/ops/cargo_rustc/mod.rs +++ b/src/cargo/ops/cargo_rustc/mod.rs @@ -278,6 +278,7 @@ fn rustc(cx: &mut Context, unit: &Unit, exec: Arc) -> CargoResult